import random
import json

def generate_test_cases():
    """生成跳跃游戏的测试用例"""
    test_cases = []
    
    # 基础测试用例
    basic_cases = [
        # 能跳到终点的情况
        [2, 3, 1, 1, 4],
        [1, 1, 1, 1, 1],
        [3, 2, 1, 0, 4],
        [1, 2, 3],
        [5],
        [1],
        [0],
        
        # 不能跳到终点的情况
        [3, 2, 1, 0, 4],
        [1, 0, 1, 0],
        [0, 1],
        [2, 0, 0],
        [1, 0, 0, 0],
    ]
    
    for case in basic_cases:
        test_cases.append({
            "input": case,
            "description": f"基础测试用例: {case}"
        })
    
    # 边界情况
    edge_cases = [
        # 单个元素
        ([0], "单个元素0"),
        ([1], "单个元素1"),
        ([5], "单个元素大于1"),
        
        # 两个元素
        ([0, 1], "两个元素[0,1]"),
        ([1, 0], "两个元素[1,0]"),
        ([2, 1], "两个元素[2,1]"),
        
        # 开头就是0
        ([0, 2, 3], "开头为0"),
        
        # 全是0
        ([0, 0, 0], "全是0"),
        
        # 很大的跳跃距离
        ([10, 0, 0, 0, 0], "很大的跳跃距离"),
    ]
    
    for case, desc in edge_cases:
        test_cases.append({
            "input": case,
            "description": desc
        })
    
    # 随机生成测试用例
    random.seed(42)  # 设置随机种子以确保可重复性
    
    for i in range(20):
        length = random.randint(1, 20)
        nums = []
        
        # 生成能跳到终点的情况
        if i % 2 == 0:
            for j in range(length):
                if j == length - 1:
                    nums.append(0)  # 最后一个元素可以是0
                else:
                    # 确保至少有一条路径能到达终点
                    max_jump = min(random.randint(1, 5), length - j)
                    nums.append(max_jump)
        else:
            # 生成可能不能跳到终点的情况
            for j in range(length):
                nums.append(random.randint(0, min(4, length - j)))
        
        test_cases.append({
            "input": nums,
            "description": f"随机生成用例 {i+1}"
        })
    
    # 性能测试用例
    performance_cases = [
        # 长数组 - 能跳到
        ([1] * 100, "长数组全1"),
        ([2] * 50, "长数组全2"),
        ([i % 3 + 1 for i in range(100)], "长数组周期性"),
        
        # 长数组 - 不能跳到
        ([1] * 50 + [0] + [1] * 49, "长数组中间有0"),
    ]
    
    for case, desc in performance_cases:
        test_cases.append({
            "input": case,
            "description": desc
        })
    
    return test_cases

def save_test_cases(filename="test_cases.json"):
    """保存测试用例到文件"""
    test_cases = generate_test_cases()
    
    with open(filename, 'w', encoding='utf-8') as f:
        json.dump(test_cases, f, ensure_ascii=False, indent=2)
    
    print(f"已生成 {len(test_cases)} 个测试用例，保存到 {filename}")
    return test_cases

if __name__ == "__main__":
    # 生成并保存测试用例
    cases = save_test_cases()
    
    # 显示部分测试用例
    print("\n部分测试用例预览:")
    for i, case in enumerate(cases[:10]):
        print(f"{i+1}. {case['description']}: {case['input']}")
